import QtQuick 1.0
import "common"

ODialog {
    id:root
    property string path
    property string fileName
    signal makeDir(string name)
    signal removed()
    signal opened()
    signal renamed(string name)

    function action(index)
    {

        switch ( index )
        {
        case 0 : dialog.show = true; break;
        case 1: dialog.show = true; lineEdit.text =root.fileName; break;
        case 2: dialog2.show = true; break;
        case 3: root.opened();break;

        }


    }

    ListModel {
        id:listModel
        ListElement {
            action : "make dir"
            actionDef:"make a new directory"
            actionIcon : "gfx/folder-new.png"
        }
        ListElement {
            action : "rename"
            actionDef:"rename file or directory"
            actionIcon : "gfx/gtk-edit.png"
        }
        ListElement {
            action : "remove"
            actionDef:"remove file or directory"
            actionIcon : "gfx/delete.png"
        }
        ListElement {
            action : "open"
            actionDef:"open file "
            actionIcon : "gfx/system-run.png"
        }

    }

    ListView {
        id:view
        width: parent.width
        height: parent.height - 60
        model:listModel
        clip: true
        delegate: OMenuItem {
            title: action
            subTitle: actionDef
            icon:actionIcon
            onClicked: {
                view.currentIndex = index
                root.action(index)
            }

        }
    }


    ODialog {
        id:dialog
        width: root.width
        height: root.height

        OLineEdit {
            id:lineEdit
            anchors.centerIn: parent
        }
        onAccept:
        {
            root.show = false
            if ( view.currentIndex == 0)
                root.makeDir(lineEdit.text)
            if ( view.currentIndex == 1)
                root.renamed(lineEdit.text)
        }

    }

    ODialog {
        id:dialog2
        width: root.width
        height: root.height

        content: "Are you sure you want to perform this action ? "


        onAccept:
        {
            root.show = false
                root.removed()
        }

    }

}
